import React, { useEffect, useState } from 'react';
import { Modal, message } from 'antd';
import Editor from '../Editor';

const EditorFile: React.FC<any> = ({ visible, onCancel, editContent, onSubmit }) => {
  const [editContents, setEditorContent] = useState<string>(editContent);

  const handleEditorChange = (content: any) => {
    setTimeout(() => {
      setEditorContent(content);
    }, 1000);
  };

  const handleOkSubmit = async () => {
    onSubmit(editContents);
  };

  return (
    <>
      <Modal
        title={'编辑/下载文件'}
        onCancel={onCancel}
        visible={visible}
        width="700px"
        okText="下载"
        cancelText="取消"
        onOk={handleOkSubmit}
      >
        <div>
          <Editor onChange={handleEditorChange} defaultValue={editContent} />
        </div>
      </Modal>
    </>
  );
};

export default EditorFile;
